package de.g18.gruppe3.common.model;

/**
 * Model für einen Benutzer
 *
 * @author <a href="mailto:kevinhuber.kh@gmail.com">Kevin Huber</a>
 */
public class User extends AbstractLDAPModel {

    public static final String PROPERTYNAME_LOGIN = "login";
    public static final String PROPERTYNAME_VORNAME = "vorname";
    public static final String PROPERTYNAME_NACHNAME = "nachname";
    public static final String PROPERTYNAME_PASSWORT = "passwort";
    public static final String PROPERTYNAME_OU = "ou";

	// Membervariablen

	private String login;
	private String vorname;
	private String nachname;
	private String passwort;
	private OrganizationalUnit ou;


	//Konstruktor

	public User() {
	}

	public User(String stLoginName, String stVorName, String stNachName) {
		setLogin(stLoginName);
		setVorname(stVorName);
		setNachname(stNachName);
	}

    // Getter & Setter

    public String getLogin() {
        return login;
    }

    public void setLogin(String aNewValue) {
        String oldValue = getLogin();
        login = aNewValue;
        firePropertyChange(PROPERTYNAME_VORNAME, oldValue, getLogin());
    }

    public String getVorname() {
        return vorname;
    }

    public void setVorname(String aNewValue) {
        String oldValue = getVorname();
        vorname = aNewValue;
        firePropertyChange(PROPERTYNAME_VORNAME, oldValue, getVorname());
    }

    public String getNachname() {
        return nachname;
    }

    public void setNachname(String aNewValue) {
        String oldValue = getNachname();
        nachname = aNewValue;
        firePropertyChange(PROPERTYNAME_NACHNAME, oldValue, getNachname());
    }

    public String getPasswort() {
        return passwort;
    }

    public void setPasswort(String aNewValue) {
        String oldValue = getPasswort();
        passwort = aNewValue;
        firePropertyChange(PROPERTYNAME_PASSWORT, oldValue, getPasswort());
    }

    public OrganizationalUnit getOU() {
        return ou;
    }

    public void setOU(OrganizationalUnit aNewValue) {
        OrganizationalUnit oldValue = getOU();
        ou = aNewValue;
        firePropertyChange(PROPERTYNAME_OU, oldValue, getOU());
    }

    public String getName() {
        return getVorname() + " " + getNachname();
    }

    @Override
    public String toString() {
        return "User[Login=" + getLogin() + ",\n"
             + "Vorname=" + getVorname() + ",\n"
             + "Nachname=" + getNachname() + ",\n"
             + "Passwort=" + getPasswort() + ",\n"
             + "Organisationseinheit=" + getOU() + "]";
    }

    @Override
    public boolean equals(Object aOtherObject) {
    	if (aOtherObject instanceof User) {
    		User otherUser = (User) aOtherObject;
    		return getLogin().equals(otherUser.getLogin())
    		    && getName().equals(otherUser.getName())
    		    && getOU().equals(otherUser.getOU());
    	}
    	return false;
    }
}
